<?php
			ob_start();			
?>
<?php
		
		if (isset($_COOKIE["user"])) {
			// if cookie <> ""
		  }
		  else
		  {
			  header("location:login.php");
			  
		  }
?>
<?php
function updatePublish($active)
{	
	$active = $active == 1 ? 0 : 1;
	$user_id_pub = $_REQUEST["user_id_pub"];
	$sql = "UPDATE tbl_user SET active={$active} WHERE user_id=$user_id_pub";
	query($sql);	
}
?>
<?php
if(isset($_REQUEST["active"]))
{
	updatePublish($_REQUEST["active"]);
	
}
?>
<?php
function deleteRecord($id_imagename)
{
	//get id from array
	$user_id = key($id_imagename);
	//get cat_image from array
	$imagename = current($id_imagename);
	$sql = "DELETE FROM tbl_user WHERE user_id={$user_id}";
	$result = query($sql);	
	if($result)
	{
		deleteFile("user/{$imagename}");
		errorMessage("Delete successful..!");
	}	
	else
	{
		errorMessage("Delete fail..!");
	}	
}
?>
<?php
	if(@is_array($_REQUEST["user_id"]))
{
	$id_imagename = $_REQUEST["user_id"];
	deleteRecord($id_imagename);
}
?>

                	<div id="border_cont_title">
                        	<div id='content_title_left'>gestion des utilisateurs</div>
                            <div id='content_title_right'><a href="#"></a></div>
					</div> <!--end border_cont_title-->
                    
                    <?php echo @$errors;?>
                    
                    	<table width="100%">
                            	<tr>
                                    <th>Nom d'utilisateur</th>
                                    <th>Connexion utilisateur</th>
                                     <th>Actif</th>
                                    <th>Action</th>
                                </tr>
                             
                                <?php
								

                                    $sql = "SELECT * from  tbl_user ORDER BY user_id DESC"; 
                                    $result = query($sql);

                                    while($row = fetch_assoc($result))
                                    {
                                ?>
                                <tr>
                                    <td align="center"><?php echo $row["full_name"];?></td>
                                    <td align="center"><?php echo $row["user_login"];?></td>
                                    <td align="center">
									<?php 
                                            $icon_publish = $row["active"]==0 ? "publish_x.png" : "publish_y.png";
                                            $publish_image = "<img width='15px' src='images/{$icon_publish}' />";														
                                        ?>
                                            <a href="index.php?page=user&active=<?php echo $row["active"] . "&user_id_pub=" . $row["user_id"];?>">
                                            <?php echo $publish_image; ?></a></td>
                                    <td align="center">
                                   <a href="index.php?page=userEdit&user_id=<?php echo $row["user_id"]?>"><img class="action_distant" src="images/edit.png"  /></a>
                                   
                                    </td>
                                </tr>
                                <?php
									}//end while

                                ?>
                            </table>
                        